import sys, clr

clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
clr.AddReference("Mono.Zeroconf")

from System.Drawing import Point
import System.Windows.Forms as wf

import Mono.Zeroconf
from Mono.Zeroconf import ServiceBrowser

class WView(wf.Form):
    def __init__(self):
        self.Text = "Share Files"
        self.Height = 500
        self.Width = 500
        self.OutermostContainer = wf.FlowLayoutPanel()
        self.OutermostContainer.FlowDirection = wf.FlowDirection.TopDown
        self.Panel = wf.FlowLayoutPanel()
        self.Panel.FlowDirection = wf.FlowDirection.LeftToRight
        self.GridContainer = wf.FlowLayoutPanel()
        self.GridContainer.FlowDirection = wf.FlowDirection.LeftToRight

        self.OutermostContainer.Width = self.Width
        self.OutermostContainer.Height = self.Height
        self.GridContainer.Width = self.OutermostContainer.Width
        self.Panel.Width = self.OutermostContainer.Width
        
        self.OutermostContainer.Dock=wf.DockStyle.Fill
        self.OutermostContainer.AutoSize = True
        self.OutermostContainer.AutoSizeMode = wf.AutoSizeMode.GrowAndShrink
        #self.GridContainer.Dock = wf.DockStyle.Fill
        self.GridContainer.AutoSize = True
        self.GridContainer.AutoSizeMode = wf.AutoSizeMode.GrowAndShrink
        #self.Panel.AutoSize = True
        #self.Panel.AutoSizeMode = wf.AutoSizeMode.GrowAndShrink


        self.addbut = wf.Button(Text="Add")
        self.addbut.Click += self._add
        self.rembut = wf.Button(Text="Remove")
        self.rembut.Click +=self._rem
        self.qbut = wf.Button(Text="Quit")
        self.qbut.Click += self._quit

        self.Panel.Controls.Add(self.addbut)
        self.Panel.Controls.Add(self.rembut)
        self.Panel.Controls.Add(self.qbut)

        self.lnet = wf.ListView()
        self.lnet.View = wf.View.Details
        self.lnet.LabelEdit = False

        self.filev = wf.ListView()
        self.filev.View = wf.View.Details
        self.filev.LabelEdit = False
        # I have no idea why -2
        self.lnet.Columns.Add("Browsing:", -2, wf.HorizontalAlignment.Center)
        self.GridContainer.Controls.Add(self.lnet)

        self.filev.Columns.Add("Files:", -2, wf.HorizontalAlignment.Center)
        self.GridContainer.Controls.Add(self.filev)

        self.OutermostContainer.Controls.Add(self.Panel)
        self.OutermostContainer.Controls.Add(self.GridContainer)

        self.Controls.Add(self.OutermostContainer)
        
        browser = ServiceBrowser()
        browser.ServiceAdded += lambda x,y: sys.stderr.write(str(args))
        browser.Browse('_fhttp._tcp','local')

    def _quit(self,*args):
        wf.Application.Exit()

    def _add(self, button, event):
        print "{stub for adding file}"

    def _rem(self, *args):
        print "{stub for removing file}"

def gcall(*args):
    print "Called w\:", str(args)

if __name__ == "__main__":
    gui = WView()
    wf.Application.Run(gui)
